//
//  CustomerView.m
//  WGFGlobalHouses
//
//  Created by waiguofang on 15/5/22.
//  Copyright (c) 2015年 waiguofang. All rights reserved.
//   真实客户

#import "CustomerView.h"
#import "StringTool.h"
#import "UIImageView+WebCache.h"

@interface CustomerView ()

@property (weak, nonatomic) IBOutlet UIImageView *headImg;
@property (weak, nonatomic) IBOutlet UILabel *nameLab;
@property (weak, nonatomic) IBOutlet UILabel *mobileLab;
@property (weak, nonatomic) IBOutlet UILabel *forbidLab;
@property (weak, nonatomic) IBOutlet UIView *rightView;
@property (weak, nonatomic) IBOutlet UIButton *selecteStatuBtn;

@property (nonatomic,strong) NSLayoutConstraint* conLay;

@end

@implementation CustomerView

+(instancetype)createView;
{
    CustomerView *view =  [[[NSBundle mainBundle]loadNibNamed:@"CustomerView" owner:nil options:nil]lastObject];
    
    for (NSLayoutConstraint *conLayout in view.constraints) {
        
        if (conLayout.firstItem==view.headImg&&conLayout.firstAttribute ==NSLayoutAttributeLeading) {
            view.conLay = conLayout;
            break;
        }
    }
    
    return view;
}


-(void)setModel:(CustomerModel *)model
{
    if (![StringTool isBlankString:model.consumerAvatar])
    {
        [self.headImg sd_setImageWithURL:[NSURL URLWithString:model.consumerAvatar] placeholderImage:[UIImage imageNamed:@"user_portiart"]];
    }
    if (![StringTool isBlankString:model.consumerName]) {
        self.nameLab.text = model.consumerName;
    }else
    {
        self.nameLab.text = @"无数据";
    }
    if (![StringTool isBlankString:model.consumerMobile]) {
        self.mobileLab.text = model.consumerMobile;
    }
    if ([model.consumerState isEqual:@"0"]) {
        self.forbidLab.hidden = YES;
    }else if ([model.consumerState isEqual:@"1"])
        self.forbidLab.hidden = NO;
    
     [self.selecteStatuBtn setHighlighted:model.isSelected];
}


-(void)setIsEditMode:(Boolean)isEditMode{
    
    [self.rightView setHidden:isEditMode];
    
    self.conLay.constant = isEditMode?40:10;
    
    [self layoutIfNeeded];
}

@end
